package com.guan.poi.core;

import java.util.Collection;
import java.util.function.Function;

/**
 * @author guan
 * @date 2019/11/15
 */
public class PoiColumns<T, V> extends PoiColumnItems<T, V> {

    public PoiColumns(ValueFunction<T, Collection<V>> valueFunction) {
        super(valueFunction);
    }

    public PoiColumns(ValueFunction<T, Collection<V>> valueFunction, String... title) {
        super(valueFunction, t1 -> title);
    }

    public PoiColumns(ValueFunction<T, Collection<V>> valueFunction, Function<V, String> title) {
        super(valueFunction, t1 -> new String[]{title.apply(t1.value())});
    }

    public <V2> PoiColumnItems<V, V2> addColumns(ValueFunction<V, Collection<V2>> valueFunction, Function<V2, String> title) {
        return addColumns(new PoiColumns<>(valueFunction, title));
    }

    public <V2> PoiColumn<V> addColumn(ValueFunction<V, V2> valueFunction, Function<V, String> titles) {
        return addColumn(new PoiColumn<>(valueFunction, item -> new String[]{titles.apply(item.value())}));
    }

    public <V2> PoiColumn<V> addColumn(ValueFunction<V, V2> valueFunction, String... titles) {
        return addColumn(new PoiColumn<>(valueFunction, item -> titles));
    }
}
